//
// Created by yunnan xu on 2020/12/4.
//

#ifndef ANDROIDGRAPHICSDEMOS_DUMMYMODEL_H
#define ANDROIDGRAPHICSDEMOS_DUMMYMODEL_H

#include "Model.h"

class DummyModel : public Model
{
public:
    /*
     * 静态工厂方法，C++17 之前不支持构造函数类型推断 （CTAD），https://en.cppreference.com/w/cpp/language/class_template_argument_deduction
     * */
    template<DummyItemType t, class ... Args>
    static std::shared_ptr<DummyModel> MakeDummyModel(std::unordered_set<VertexAttribType> attrib_list, bool with_rb, Args ... args);

    virtual ~DummyModel();
    virtual int GetVertexNumber() const;
    virtual int GetFaceNumber() const;
    virtual const void * GetVertexData(VertexAttribType attrib_type) const;
    virtual size_t GetVertexDataLength(VertexAttribType attrib_type) const;
    virtual const void * GetIndexData() const;
    virtual size_t GetIndexDataLength() const;
    virtual GLenum GetIndexType() const;

    const glm::mat4 & GetModelMatrix() const;

private:

    int vertexNumber;
    int faceNumber;

    std::unordered_map<VertexAttribType, uint8_t*> vertex_data;
    uint8_t * index_data;

    // index 类型，对于 gles 就是 GL_UNSIGNED_BYTE, GL_UNSIGNED_SHORT, or GL_UNSIGNED_INT 三选一，
    // https://www.khronos.org/registry/OpenGL-Refpages/es3.0/html/glDrawElements.xhtml
    GLenum index_type;
};

template<>
std::shared_ptr<DummyModel>
DummyModel::MakeDummyModel<DummyItemType::Plane>(std::unordered_set<VertexAttribType> attrib_list, bool with_rb, float w, float h);

template<>
std::shared_ptr<DummyModel>
DummyModel::MakeDummyModel<DummyItemType::Triangle>(std::unordered_set<VertexAttribType> attrib_list, bool with_rb, float side_length);

template<>
std::shared_ptr<DummyModel>
DummyModel::MakeDummyModel<DummyItemType::Box>(std::unordered_set<VertexAttribType> attrib_list, bool with_rb, float l, float w, float h);

template<>
std::shared_ptr<DummyModel>
DummyModel::MakeDummyModel<DummyItemType::Sphere>(std::unordered_set<VertexAttribType> attrib_list, bool with_rb, float r, int warp_number);


template<>
std::shared_ptr<DummyModel>
DummyModel::MakeDummyModel<DummyItemType::Icosahedron>(std::unordered_set<VertexAttribType> attrib_list, bool with_rb, float r);


#endif //ANDROIDGRAPHICSDEMOS_DUMMYMODEL_H
